/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.intercoop_inland.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.intercoop_inland.entity.TbIntercoopInland;
import com.thinkgem.jeesite.modules.intercoop_inland.service.TbIntercoopInlandService;

/**
 * 境外学生来华学习交流Controller
 * @author hang
 * @version 2017-01-14
 */
@Controller
@RequestMapping(value = "${adminPath}/intercoop_inland/tbIntercoopInland")
public class TbIntercoopInlandController extends BaseController {

	@Autowired
	private TbIntercoopInlandService tbIntercoopInlandService;
	
	@ModelAttribute
	public TbIntercoopInland get(@RequestParam(required=false) String id) {
		TbIntercoopInland entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tbIntercoopInlandService.get(id);
		}
		if (entity == null){
			entity = new TbIntercoopInland();
		}
		return entity;
	}
	
	@RequiresPermissions("intercoop_inland:tbIntercoopInland:view")
	@RequestMapping(value = {"list", ""})
	public String list(TbIntercoopInland tbIntercoopInland, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TbIntercoopInland> page = tbIntercoopInlandService.findPage(new Page<TbIntercoopInland>(request, response), tbIntercoopInland); 
		model.addAttribute("page", page);
		return "modules/intercoop_inland/tbIntercoopInlandList";
	}

	@RequiresPermissions("intercoop_inland:tbIntercoopInland:view")
	@RequestMapping(value = "form")
	public String form(TbIntercoopInland tbIntercoopInland, Model model) {
		model.addAttribute("tbIntercoopInland", tbIntercoopInland);
		return "modules/intercoop_inland/tbIntercoopInlandForm";
	}

	@RequiresPermissions("intercoop_inland:tbIntercoopInland:edit")
	@RequestMapping(value = "save")
	public String save(TbIntercoopInland tbIntercoopInland, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tbIntercoopInland)){
			return form(tbIntercoopInland, model);
		}
		tbIntercoopInlandService.save(tbIntercoopInland);
		addMessage(redirectAttributes, "保存境外学生来华学习交流成功");
		return "redirect:"+Global.getAdminPath()+"/intercoop_inland/tbIntercoopInland/?repage";
	}
	
	@RequiresPermissions("intercoop_inland:tbIntercoopInland:edit")
	@RequestMapping(value = "delete")
	public String delete(TbIntercoopInland tbIntercoopInland, RedirectAttributes redirectAttributes) {
		tbIntercoopInlandService.delete(tbIntercoopInland);
		addMessage(redirectAttributes, "删除境外学生来华学习交流成功");
		return "redirect:"+Global.getAdminPath()+"/intercoop_inland/tbIntercoopInland/?repage";
	}

}